﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">预收单号</label>
                        <div class="layui-input-block">
                            <input type="text" name="txt_ysdh" id="txt_ysdh" placeholder="预收单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">量定单号</label>
                        <div class="layui-input-block">
                            <input type="text" name="txt_orderdh" id="txt_orderdh" placeholder="请输入量定单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">款号</label>
                        <div class="layui-input-block">
                            <input type="text" name="txt_kh" id="txt_kh" placeholder="请输入款号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">审批状态</label>
                        <div class="layui-input-block">
                            <select name="status" id="status">
                                <option value="">全部</option>
                                <option value="0">未提交</option>
                                <option value="-1">驳回</option>
                                <option value="1" selected>提交</option>
                                <option value="99">审核通过</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <!--<button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>-->
                    <!--<button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>-->
                </div>


                <script type="text/html" id="test-table-operate-td">
                    {{#  if(d.status == 1){ }}
                    <a class="layui-btn layui-btn-xs" lay-event="audit">审核</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="return_order">驳回</a>
                    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                    {{#  } else { }}
                    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                    {{#  } }}
                </script>
                <script type="text/html" id="buttonTpl">
                    {{#  if(d.status == 99){ }}
                    <button class="layui-btn layui-btn-xs">已审核</button>
                    {{#  } else if(d.status == 1){ }}
                    <button class="layui-btn layui-btn-primary layui-btn-xs">已提交</button>
                    {{#  } else if(d.status == 0){ }}
                    <button class="layui-btn layui-btn-primary layui-btn-xs">未提交</button>
                    {{#  } else if(d.status == -1){ }}
                    <button class="layui-btn layui-btn-danger layui-btn-xs">驳回</button>
                    {{#  } else { }}
                    <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                    {{#  } }}
                </script>
                <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
                <script type="text/html" id="imgTpl">
                    <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
                </script>
                <!--<script type="text/html" id="table-useradmin-webuser">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>-->
            </div>


        </div>
    </div>
    <script src="../../layuiadmin/js/jquery.min2.1.4.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script src="../../layuiadmin/js/cookie.js"></script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'useradmin', 'table'], function () {
            var $ = layui.$
                , form = layui.form
                , table = layui.table;
            //加载表格
            table.render({
                elem: '#LAY-user-manage'
                , id: 'testReload'//容器的ID
                , url: 'ashx/list.ashx?type=getshlist'
                , toolbar: '#test-table-radio-toolbarDemo'
                , method: 'post'
                , page: true
                , limits: [10, 20, 30]
                , limit: 10
                , cols: [[
                    { type: 'checkbox' }
                    , { field: 'id', width: 60, title: 'id', align: 'center' }
                    , { field: 'rebh', width: 180, title: '返修单号', align: 'center' }
                    , { field: 'ysdh', width: 180, title: '预收单号', align: 'center' }
                    , { field: 'name', width: 120, title: '品名', align: 'center' }
                    , { field: 'kh', width: 150, title: '款号', align: 'center' }
                    , { field: 'sl', width: 100, title: '数量', align: 'center' }
                    , { field: 'remark', width: 200, title: '返修原因', align: 'center' }
                    , { field: 'status', width: 100, title: '状态', align: 'center', templet: '#buttonTpl' }
                    , { field: 'username', width: 100, title: '创建人', align: 'center' }
                    //, { field: 'imgurl', width: 100, title: '图片地址', align: 'center', templet: img }
                    , { field: 'createtime', width: 180, title: '创建时间', align: 'center', sort: true }
                    , { width: 178, align: 'center', fixed: 'right', toolbar: '#test-table-operate-td' }

                ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
                , where: {
                    txt_ysdh: $('#txt_ysdh').val(),
                    txt_orderdh: $('#txt_orderdh').val(),
                    txt_kh: $('#txt_kh').val(),
                    status: $("select[name='status']").val()
                }
            });

            //监听排序
            table.on('sort(LAY-user-manage)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                table.reload('testReload', {//刷新列表
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                    , where: { //请求参数
                        field: obj.field, //排序字段
                        order: obj.type, //排序方式
                        txt_ysdh: $('#txt_ysdh').val(),
                        txt_orderdh: $('#txt_orderdh').val(),
                        txt_kh: $('#txt_kh').val(),
                        status: $("select[name='status']").val()

                    }
                });
            });
            //双击行事件
            table.on('rowDouble(LAY-user-manage)', function (obj) {
                //console.log(obj.tr) //得到当前行元素对象
                //console.log(obj.data) //得到当前行数据
                layer.open({
                    type: 2
                    , title: '查看'
                    , content: 'select_ls.html?&dj_docno=' + obj.data.rebh
                    , maxmin: true
                    , area: [($(window).width() * 0.7) + 'px', ($(window).height() * 0.7) + 'px']
                    , cancel: function (index, layero) {

                    },
                    end: function () {

                    }
                });
                //obj.del(); //删除当前行
                //obj.update(fields) //修改当前行数据
            });
            //监听工具条
            table.on('tool(LAY-user-manage)', function (obj) {
                var data = obj.data;
                //查看明细
                if (obj.event === 'detail') {
                    layer.open({
                        type: 2
                        , title: '查看'
                        , content: 'edit.html?editid=' + data.id
                        , maxmin: true
                        , area: ['700px', '750px']

                    }); 
                }

                //驳回
                else if (obj.event == 'return_order') {
                    layer.prompt({ title: '请填写驳回意见，并确认', formType: 2 }, function (text, index) {
                        $.ajax({
                            url: 'ashx/list.ashx?type=return_order&getids=' + data.id + '&return_remark=' + text + '&userid=' + $.cookie("id") + '&usernames=' + $.cookie("username") + '&docno=' + data.rebh,
                            type: "post",
                            contentType: "application/json",
                            dataType: "json",
                            data: {},
                            success: function (res) {
                                if (res.flag == "True") {
                                    layer.close(index);
                                    layer.msg(res.remsg, {
                                        time: 2000,
                                        end: function () {
                                            table.reload('testReload', {//刷新列表
                                                where: { //请求参数
                                                    txt_ysdh: $('#txt_ysdh').val(),
                                                    txt_orderdh: $('#txt_orderdh').val(),
                                                    txt_kh: $('#txt_kh').val(),
                                                    status: $("select[name='status']").val()
                                                }
                                            });
                                        }
                                    })
                                }
                                else {
                                    layer.alert(res.remsg);
                                }
                            }
                        });
                    });
                }
                //审核
                else if (obj.event == 'audit') {
                    layer.confirm('确定审核吗', function (index) {
                        $.ajax({
                            url: 'ashx/list.ashx?type=audit&getids=' + data.id + '&userid=' + $.cookie("id") + '&usernames=' + $.cookie("username") + '&docno=' + data.rebh,
                            type: "post",
                            contentType: "application/json",
                            dataType: "json",
                            data: {},
                            success: function (res) {
                                var index = parent.layer.getFrameIndex(window.name);
                                if (res.flag == "True") {
                                    layer.msg(res.remsg, {
                                        time: 2000,
                                        end: function () {
                                            table.reload('testReload', {//刷新列表
                                                where: { //请求参数
                                                    txt_ysdh: $('#txt_ysdh').val(),
                                                    txt_orderdh: $('#txt_orderdh').val(),
                                                    txt_kh: $('#txt_kh').val(),
                                                    status: $("select[name='status']").val()
                                                }
                                            });
                                        }
                                    })
                                }
                                else {
                                    layer.alert(res.remsg);
                                }
                            }
                        });
                    });
                }

            });
            //监听搜索
            form.on('submit(LAY-user-front-search)', function (data) {
                var field = data.field;
                //执行重载
                table.reload('testReload', {
                    where: {
                        txt_ysdh: $('#txt_ysdh').val(),
                        txt_orderdh: $('#txt_orderdh').val(),
                        txt_kh: $('#txt_kh').val(),
                        status: $("select[name='status']").val()

                    }, page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });


            $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });


    </script>
</body>
</html>
